#ifndef COLLECTOR_H
#define COLLECTOR_H

#include <QtService>
#include "support/mysql_helper.h"
#include <head/g_functionbase.h>
#include "element/baseudpreceiver.h"
#include "g_ver.h"
#include "m_fhs.h"

class Collector : public QObject
{
    Q_OBJECT
public:
    explicit Collector(QObject *parent = nullptr);

    bool connectDB();
    void dbTry();

    void start();
    void stop();
    void appendLog(const QString &event,
                   QtServiceBase::MessageType type=QtServiceBase::Information);

    bool addMessage(const QString &source,
                    const QString &type,
                    const QString &level,
                    const QString &content);

    void receivedMessage(const QByteArray &data);
    void startReceiver();
    void stopReceiver();

private:
    QSqlDatabase db;
    QString table;

    BaseUdpReceiver *receiver;
    QThread recvThread;
};

#endif // COLLECTOR_H
